/*
 * @Author: silence
 * @Date: 2023-08-18 10:23:38
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-10-18 10:30:04
 * @Description: 配网第五步（结果）：配网结果
 */
import 'package:ems_neutral_app/pages/Mine/Language/SilLocalizations/SilLocalizations.dart';
import 'package:flutter/material.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../base/SilScaffold.dart';
import '../../common/widgets/cubitWidget/SubmitBtn.dart';
import '../../utils/color/ColorUtils.dart';
import 'DNCheckDevicePage.dart';

class DNSetResultPage extends StatefulWidget {
  final bool isSuccess;
  const DNSetResultPage({this.isSuccess = true, super.key});

  @override
  State<DNSetResultPage> createState() => _DNSetResultPageState();
}

class _DNSetResultPageState extends State<DNSetResultPage> {
  @override
  Widget build(BuildContext context) {
    return SilScaffold(
      title: widget.isSuccess
          ? LangOf(context)?.deviceNetworking?.deviceNetworkingSuccess
          : LangOf(context)
              ?.deviceNetworking
              ?.deviceNetworkingFail, //'设备联网成功' : '设备联网失败',
      body: mainWidget(),
    );
  }

  mainWidget() {
    return widget.isSuccess ? successView() : failView();
  }

  successView() {
    return ListView(
      children: [
        /// 图片
        Container(
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 65.w),
          child: SilImage(
            'imgs/device_net/device_net_device_flag.png',
            margin: EdgeInsets.only(top: 30.w),
          ),
        ),
        SilText(
          LangOf(context)
              ?.deviceNetworking
              ?.deviceNetworkingSuccessPrompt, //'设备重启后，如果出现NET/LINK指示灯未点亮，请按照正确的操作步骤重新配网',
          margin: EdgeInsets.only(top: 20.w, bottom: 20.w),
          color: ColorUtils.color_font_main,
          fontSize: 14.sp,
          maxLines: 0,
          lineHeight: 1.5.w,
        ),
        SubmitBtn(
          title: LangOf(context)?.deviceNetworking?.back, //'返回',
          onTapFunc: () {
            Navigator.popUntil(context, (ModalRoute.withName('/')));
          },
          margin: EdgeInsets.only(
              top: 10.w, bottom: MediaQuery.of(context).padding.bottom + 10.w),
        )
      ],
    );
  }

  failView() {
    return Column(
      children: [
        Expanded(child: failPromptView()),
        SubmitBtn(
          title: LangOf(context)?.deviceNetworking?.reset, //'重新设置',
          onTapFunc: () {
            Navigator.popUntil(
                context,
                (route) =>
                    route.settings.name ==
                    DNCheckDevicePage.route().settings.name);
          },
          margin: EdgeInsets.only(top: 10.w),
        ),
        SubmitBtn(
          title: LangOf(context)?.deviceNetworking?.back, //'返回',
          onTapFunc: () {
            Navigator.popUntil(context, ModalRoute.withName('/'));
          },
          margin: EdgeInsets.only(
              top: 10.w, bottom: MediaQuery.of(context).padding.bottom + 10.w),
        )
      ],
    );
  }

  /// 失败提示
  failPromptView() {
    return ListView(children: [
      Padding(padding: EdgeInsets.only(top: 20.w)),

      /// 提示文字
      SilText(
        LangOf(context)
            ?.deviceNetworking
            ?.deviceNetworkingFailPrompt, //'请检查一下信息：\n\n1、检查设备是否开机，保持电量在20%以上\n2、请确定Wi—Fi网络为2.4GHz网络，输入的Wi—Fi名称和密码正确\n3、将设备放在离路由器近一些的地方，确保网络稳定',
        color: ColorUtils.color_font_main,
        fontSize: 14.sp,
        maxLines: 0,
        lineHeight: 1.5.w,
      ),

      /// 图片
      Container(
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 65.w),
        child: SilImage(
          'imgs/device_net/device_net_device_flag.png',
          margin: EdgeInsets.only(top: 30.w),
        ),
      )
    ]);
  }
}
